//
//  LKHomeHeaderCell.m
//  YLHelper
//
//  Created by she1323 on 2018/4/12.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKHomeHeaderCell.h"
#import "LKHomeCycleImagesViewModel.h"
#import "LKHomeCycleImagesModel.h"
@interface LKHomeHeaderCell()<SDCycleScrollViewDelegate>

@property(nonatomic,strong)SDCycleScrollView *cycleScrollView;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property(nonatomic,strong)LKHomeCycleImagesViewModel *imagesViewModel;

@property(nonatomic,strong)NSMutableArray *redirectUrlArray;
@end

@implementation LKHomeHeaderCell


-(RACSubject *)helpPushSubject{
    if (!_helpPushSubject) {
        _helpPushSubject = [RACSubject subject];
    }
    return _helpPushSubject;
}
-(LKHomeCycleImagesViewModel *)imagesViewModel{
    if (!_imagesViewModel) {
        _imagesViewModel = [[LKHomeCycleImagesViewModel alloc] init];
    }
    return _imagesViewModel;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    [self setUpUI];
}
- (void)setUpUI
{
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, WIDTH, self.bgView.frame.size.height) imageNamesGroup:@[@"banner",@"banner",@"banner"]];
    cycleScrollView.delegate = self;
    cycleScrollView.currentPageDotColor = [UIColor whiteColor];
    cycleScrollView.pageDotColor = COLOR_HEX(0xA2AEFF);
    _cycleScrollView = cycleScrollView;
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.autoScrollTimeInterval = 3.0;
    [self.bgView addSubview:cycleScrollView];
    [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.bgView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    WS(weakSelf)
    [[self.imagesViewModel.requesrCommand execute:nil] subscribeNext:^(id  _Nullable x) {
        NSMutableArray *imagsUrlArray = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in weakSelf.imagesViewModel.imgaesArray) {
            LKHomeCycleImagesModel *model = [LKHomeCycleImagesModel modelWithDictionary:dic];
            [imagsUrlArray addObject:[NSString stringWithFormat:@"%@%@",ServerlUrl,model.url]];
            [weakSelf.redirectUrlArray addObject:[NSString stringWithFormat:@"%@",[NSString judegeIsNullAndTransform:model.redirectUrl]]];
        }
        weakSelf.cycleScrollView.imageURLStringsGroup = imagsUrlArray;
    }];
    
}
-(NSMutableArray *)redirectUrlArray{
    if (!_redirectUrlArray) {
        _redirectUrlArray = [[NSMutableArray alloc] init];
    }
    return _redirectUrlArray;
}
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
//    LKWebViewController *webvc = [[LKWebViewController alloc] init];
//    webvc.url = self.redirectUrlArray[index];
    if ([self.redirectUrlArray[index] isEqual:@""]) {
        return;
    }
    if (self.linkBlock) {
        self.linkBlock(self.redirectUrlArray[index]);
    }
//    [self.helpPushSubject sendNext:self.redirectUrlArray[index]];
//    [self.helpPushSubject sendCompleted];
    
    NSLog(@"跳转了");
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}


@end
